using System;
using System.Data;
using Drawing = System.Drawing;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Toenda.TFL.Base;
using Toenda.Rails.System;
using Toenda.Rails.DataContainer;

public partial class Controls_Main_ctrl_profile : System.Web.UI.UserControl {
	private AccountProvider ap = new AccountProvider();
	private StaticProvider sp = new StaticProvider();

	/// <summary>
	/// Page_Load
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e) {
		if(Request.QueryString.Get("user") != null) {
			string user = Request.QueryString.Get("user").ToString();

			if(ap.CheckUsernameExist(user)) {
				Account acc = ap.GetAccountByUsername(user);

				// avatar
				HyperLink av = new HyperLink();
				av.CssClass = "avatarImg";
				av.NavigateUrl = "~/images/" + acc.Username + "/default.aspx";

				if(acc.Avatar != "" && acc.Avatar != null) {
					av.ImageUrl = "~/Avatar/" + acc.Avatar;
				}
				else {
					av.ImageUrl = "~/App_Themes/Default/Images/avatar_placeholder.jpg";
				}

				userAvatar.Controls.Add(av);
				userAvatar.Controls.Add(new LiteralControl(""));

				// first slash
				Label litSlashOne = new Label();
				litSlashOne.CssClass = "txtSmallGreen";
				litSlashOne.Text = "/";

				userText.Controls.Add(litSlashOne);

				// link dashboard
				Label linkDash = new Label();
				linkDash.CssClass = "txtH2";
				linkDash.Text = GetLocalResourceObject("Profile").ToString();

				userText.Controls.Add(linkDash);

				// second slash
				Label litSlashTwo = new Label();
				litSlashTwo.CssClass = "txtSmallGreen";
				litSlashTwo.Text = "/";

				userText.Controls.Add(litSlashTwo);

				// link user
				Label linkUser = new Label();
				linkUser.CssClass = "txtH2";
				linkUser.Text = acc.Username;

				userText.Controls.Add(linkUser);

				// second slash
				Label litSlashThree = new Label();
				litSlashThree.CssClass = "txtSmallGreen";
				litSlashThree.Text = " (";

				userText.Controls.Add(litSlashThree);

				// link user
				Label linkUserReal = new Label();
				linkUserReal.CssClass = "txtH3";
				linkUserReal.Text = acc.Firstname + " " + acc.Lastname;

				userText.Controls.Add(linkUserReal);

				// second slash
				Label litSlashFour = new Label();
				litSlashFour.CssClass = "txtSmallGreen";
				litSlashFour.Text = ")";

				userText.Controls.Add(litSlashFour);

				/*
				 * load data
				 */

				// desc
				if(acc.Description.Trim() != "") {
					Label lblText = new Label();
					lblText.CssClass = "txtNormal";
					lblText.Text = acc.Description;

					plcData.Controls.Add(lblText);
					plcData.Controls.Add(new LiteralControl("<br /><br />"));
				}

				Label my = new Label();
				my.CssClass = "editBoxTitle";
				my.Text = GetLocalResourceObject("Personal").ToString();

				plcData.Controls.Add(new LiteralControl("<br />"));
				plcData.Controls.Add(my);
				plcData.Controls.Add(new LiteralControl("<br />"));

				// name
				if(acc.Firstname.Trim() != "" && acc.Lastname.Trim() != "") {
					Label myname = new Label();
					myname.CssClass = "txtNormal";
					myname.Text = GetLocalResourceObject("MyNameIs").ToString();
					myname.Text += " <strong>" + acc.Firstname;
					myname.Text += " " + acc.Lastname + "</strong> ";

					myname.Text += GetLocalResourceObject("AndIComeFrom").ToString();

					if(acc.Location.Trim() != "") {
						myname.Text += " <strong>";
						myname.Text += acc.Location;
						myname.Text += "</strong>";
					}

					if(acc.Location.Trim() != ""
					&& acc.Country.Trim() != "") {
						myname.Text += ", ";
					}
					else {
						myname.Text += " ";
					}

					if(acc.Country.Trim() != "") {
						Static stc = sp.GetStaticItem("C001", acc.Country);
						myname.Text += "<strong>";
						myname.Text += stc.Content;
						myname.Text += "</strong>";
					}

					plcData.Controls.Add(myname);
					plcData.Controls.Add(new LiteralControl("<br /><br />"));
				}

				// webpage
				if(acc.Webpage.Trim() != "") {
					Label myweb = new Label();
					myweb.CssClass = "txtNormal";
					myweb.Text = GetLocalResourceObject("MyWebpage").ToString();
					myweb.Text += "<br />";

					plcData.Controls.Add(myweb);

					HyperLink link = new HyperLink();
					link.CssClass = "normal";
					link.Target = "_blank";
					link.Text = (acc.WebpageName.Trim() != "" ? acc.WebpageName : acc.Webpage);
					link.NavigateUrl = acc.Webpage;

					plcData.Controls.Add(link);
					plcData.Controls.Add(new LiteralControl("<br /><br />"));
				}

				Label myContact = new Label();
				myContact.CssClass = "editBoxTitle";
				myContact.Text = GetLocalResourceObject("Contact").ToString();

				plcData.Controls.Add(new LiteralControl("<br />"));
				plcData.Controls.Add(myContact);
				plcData.Controls.Add(new LiteralControl("<br />"));

				// email
				if(acc.Email.Trim() != "") {
					Label myEmail = new Label();
					myEmail.CssClass = "txtNormal";
					myEmail.Text = GetLocalResourceObject("YouCanWriteMeAEmail").ToString();
					myEmail.Text += "<br />";

					plcData.Controls.Add(myEmail);

					HyperLink linkEmail = new HyperLink();
					linkEmail.CssClass = "normal";
					linkEmail.Text = acc.Email.Replace("@", "[AT]");
					linkEmail.NavigateUrl = "mailto:" + acc.Email.Replace("@", "[AT]");

					plcData.Controls.Add(linkEmail);
					plcData.Controls.Add(new LiteralControl("<br /><br />"));
				}
			}
			else {
				Label not = new Label();
				not.CssClass = "txtNormal";
				not.Text = GetLocalResourceObject("UserDoesNotExists").ToString();

				plcData.Controls.Add(not);
			}
		}
		else {
			Response.Redirect("~/default.aspx?id=dashboard");
		}
	}
}
